%% Thie file mainForTestn.m is the main to test the game for different n's
%% and for each of them truns times packages of nGames games
%%
%%clear;

tns = 4;
truns = 100;
thitMean = zeros(truns,tns);
thitStandardDeviation = zeros(truns,tns);
tnDroppedMean = zeros(truns,tns);
tnDroppedStandardDeviation = zeros(truns,tns);
tturnMean = zeros(truns,tns);
tturnStandardDeviation = zeros(truns,tns);
alpha = 0.05; % for confidence intervals

for n=1:tns
    %parameters
    graphSize = inf;
    timeLag = 3;
    stay = false;   %if the ship can stay at a node, this is true          %for n-restricted graphs
    graph = nRestrictedGraph(n,graphSize, timeLag, stay);
    pShip = (sqrt(n*n+4)-n)/2;
%     if n==1
%         pShip = 2/3;
%     elseif n==2
%         pShip = 5/2-0.5*sqrt(17);
%     elseif n==3
%         pShip = 7/4-1/4*sqrt(33);
%     else
%         pShip = 3/2-1/6*sqrt(57);
%     end
        
    nBombs = 1;     %number of bombs the bomber has
    nGames = 100;   %number of games to be played
    timeLimit = inf;
    ship = 1;       % 1=shipFerguson, 2=shipLeeLee, 3= shipStandStill
    bomber = 2;     % 1=bomberFerguson, 2=bomberGeneric, 3=bomberGeneric with pShip
    
    %only for printing the graph
    %print = biograph(graph);
    %view(print)
    
    
    %creating testfile
    for tj=1:truns
        %end creating testfile
        
        %store every single outcome, so we can perfrom statistics on it later
        hit = zeros(nGames,1);          %hit(i) is true if the bomber hit the ship in the ith game
        nDropped = zeros(nGames,1);     %nDropped(i) is the number of bombs that were dropped in the ith game
        turn = zeros(nGames,1);         %turn(i) is the number of turns it took until game i was finished

        %play the games
        for i=1:nGames
            [h,nD,t] = game(graph, graphSize, pShip, nBombs, timeLag, n, timeLimit, ship, bomber);
            hit(i) = h;
            nDropped(i) = nD;
            turn(i) = t;
        end
        
        %creating testfile
        n
        tj
        thitMean(tj,n) = mean(hit);
        thitStandardDeviation(tj,n) = std(hit);
        tnDroppedMean(tj,n) = mean(nDropped);
        tnDroppedStandardDeviation(tj,n) = std(nDropped);
        tturnMean(tj,n) = mean(turn);
        tturnStandardDeviation(tj,n) = std(turn);
    end
end


%save the data in an xls file
for n=1:tns
    infoWrite = zeros(truns+4,19);
    
    [muHit, sigHit, muCiHit, sigCiHit] = normfit(thitMean(:,n),alpha);
    [muDropped, sigDropped, muCiDropped, sigCiDropped] = normfit(tnDroppedMean(:,n),alpha);
    [muTurn, sigTurn, muCiTurn, sigCiTurn] = normfit(tturnMean(:,n),alpha);
    
    infoWrite(2,2) = muHit;
    infoWrite(2,3) = sigHit;
    infoWrite(2,4) = muCiHit(1);
    infoWrite(2,5) = muCiHit(2);
    infoWrite(2,6) = sigCiHit(1);
    infoWrite(2,7) = sigCiHit(2);
    infoWrite(2,8) = muDropped;
    infoWrite(2,9) = sigDropped;
    infoWrite(2,10) = muCiDropped(1);
    infoWrite(2,11) = muCiDropped(2);
    infoWrite(2,12) = sigCiDropped(1);
    infoWrite(2,13) = sigCiDropped(2);
    infoWrite(2,14) = muTurn;
    infoWrite(2,15) = sigTurn;
    infoWrite(2,16) = muCiTurn(1);
    infoWrite(2,17) = muCiTurn(2);
    infoWrite(2,18) = sigCiTurn(1);
    infoWrite(2,19) = sigCiTurn(2);
    
    muHit
    
    for j=1:truns
        infoWrite(j+4,1) = j;
        infoWrite(j+4,2) = thitMean(j,n);
        infoWrite(j+4,3) = thitStandardDeviation(j,n);
        infoWrite(j+4,4) = tnDroppedMean(j,n);
        infoWrite(j+4,5) = tnDroppedStandardDeviation(j,n);
        infoWrite(j+4,6) = tturnMean(j,n);
        infoWrite(j+4,7) = tturnStandardDeviation(j,n);
    end
    
    
    xlswrite('testresultsXYZ.xlsx',infoWrite,n);
    clear infoWrite;
end

%end creating testfile
